﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoyEngine;

namespace RedisTest
{
    class Program
    {
        private const int N = 10;
        static void Main(string[] args)
        {
            string host = "127.0.0.1";
            Roy roy = new Roy(host, 6379, "ssm123", 4);
            Stopwatch sw = new Stopwatch();

            //List<Player> articles = new List<Player>();
            //for (int i = 0; i < N; i++)
            //{
            //    Player article = new Player()
            //    {
            //        Name = "超级少年" + i,
            //        Power = 10 + i,
            //        Items = new List<string>(){ "a", "b", "c"}
            //    };
            //    articles.Add(article);
            //}
            //sw.Start();
            //foreach (var art in articles)
            //{
            //    roy.Save(art);
            //}
            //sw.Stop();
            //Console.WriteLine(sw.ElapsedMilliseconds);

            //List<Player> articlesOut = new List<Player>();
            //sw.Reset();
            //sw.Restart();
            //foreach (var art in articles)
            //{
            //    Player outer = roy.Get<Player>(art.Id);
            //    articlesOut.Add(outer);
            //}
            //sw.Stop();
            //Console.WriteLine(sw.ElapsedMilliseconds);


            //foreach (Player player in articlesOut)
            //{
            //    long rank = roy.Rank(player, "Power");
            //    Console.WriteLine("Player:{0}, Power:{1}, Rank:{2}", player.Name, player.Power, rank);
            //}
            //foreach (var player in roy.GetAll<Player>())
            //{
            //    Console.WriteLine(player);
            //}

            //int rank = 0;
            //foreach (var player in roy.Range<Player>("Power", 0, 5))
            //{
            //    Console.WriteLine("Player:{0}, Power:{1}, Rank:{2}", player.Name, player.Power, rank++);
            //}
            //Player player = new Player()
            //{
            //    Name = "小歪",
            //    Power = 1123,
            //    IsAdult = false,
            //    Items = new List<string>()
            //    {
            //        "haha",
            //        "你好"
            //    }
            //};
            //roy.Save(player);

            string pid = "4db0";
            //for (int i = 0; i < N; i++)
            //{
            //    Player p = new Player()
            //    {
            //        IsAdult = (i%2)==0,
            //        Name = i+"号",
            //        Power = 10+i,
            //        Stones = new List<string>() { "好石头", "坏石头"}
            //    };
            //    roy.Save(p);
            //    if (pid == null)
            //    {
            //        pid = p.Id;
            //    }
            //}

            //for (int i = 0; i < 10; i++)
            //{
            //    Item item = new Item()
            //    {
            //        PId = "4db1",
            //        Name = "BBB" + i + "号"
            //    };
            //    roy.Save(item);
            //}
            string uid = roy.GetHashUId("asd1");
            Console.Read();

        }


        static private void ShowRange(Roy roy)
        {
            int rank = 0;
            foreach (var player in roy.Range<Player>("Power", 0, 5))
            {
                Console.WriteLine("Player:{0}, Power:{1}, Rank:{2}", player.Name, player.Power, rank++);
            }
        }
    }



}
